﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ObviousCode.UI.Aspect.TestHarness.Objects;
using System.ComponentModel;
using System.Reflection;
using ObviousCode.Common.Utils.Library.Dictionaries;
using ZooKeeperSample.Interfaces;

namespace ZooKeeperSample.AnimalRegister.Animals
{
    public class Animal<T> : IPropertiesHost, IAnimal<T> where T : IAnimal, new()
    {
        PropertyDictionary _properties;

        public Animal()
        {

            _properties = new PropertyDictionary();

            Id = Guid.NewGuid().ToString();
            Gender = Gender.Male;
            Name = "New Animal";
            Weight = 0;
            Size = 0;
        }

        public string Name
        {
            get { return _properties.StringFor("name"); }
            set
            {
                _properties.Set("name", value);

                NotifyPropertyChange("Name");
            }
        }

        public Gender Gender
        {
            get { return _properties.EnumFor<Gender>("gender"); }
            set
            {
                _properties.Set("gender", value);

                NotifyPropertyChange("Gender");
            }
        }

        public int Weight
        {
            get { return _properties.IntFor("weight"); }
            set
            {
                _properties.Set("weight", value);

                NotifyPropertyChange("Weight");
            }
        }

        public int Size
        {
            get { return _properties.IntFor("size"); }
            set
            {
                _properties.Set("size", value);

                NotifyPropertyChange("Size");
            }
        }

        [Browsable(false)]
        public string Id
        {
            get { return _properties.StringFor("id"); }
            private set { _properties.Set("id", value); }
        }

        [Browsable(false)]
        public string GroupingTag { get; set; }

        public void NotifyPropertyChange(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        [Browsable(false)]
        public PropertyDictionary Properties
        {
            get { return _properties; }
            set { _properties = value; }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    }
}
